﻿<mydc:GazeWindow x:Class="Domotica.Media.MainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:mydc="clr-namespace:Domotica.Windows.Controls;assembly=Domotica.Windows"
    xmlns:mydi="clr-namespace:Domotica.Windows.Input;assembly=Domotica.Windows"
    xmlns:src="clr-namespace:Domotica.Media"
    Title="Domotica Music Player" Height="512" Width="619">
    <Window.CommandBindings>
        <CommandBinding Command="MediaCommands.Play"
                         Executed="CommandPlay" />
        <CommandBinding Command="MediaCommands.Stop"
                         Executed="CommandStop" />
        <CommandBinding Command="MediaCommands.NextTrack"
                         Executed="CommandNextTrack" />
        <CommandBinding Command="MediaCommands.PreviousTrack"
                         Executed="CommandPreviousTrack" />
    </Window.CommandBindings>
    <Window.Resources>
        <ResourceDictionary>
            <Style x:Key="WrapItemTemplate" TargetType="{x:Type ListBox}">
                <Setter Property="ItemTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel VerticalAlignment="Top">
                                <Image Name="Cover" Width="130" Height="130" Margin="10" 
                                        Source="{Binding Path=AlbumArtName}" VerticalAlignment="Top">
                                </Image>
                                <TextBlock Name="AlbumName" Width="Auto" MaxWidth="130" 
                                        Text="{Binding Path=Name}" 
                                        HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" FontWeight="Bold" />
                                    <TextBlock Name="ArtistName" Width="Auto"  
                                        Text="{Binding Path=Artist.Name}" 
                                        HorizontalAlignment="Center" TextWrapping="Wrap" TextAlignment="Center" />
                                </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ItemsPanel">
                    <Setter.Value>
                        <ItemsPanelTemplate>
                            <WrapPanel />
                        </ItemsPanelTemplate>
                    </Setter.Value>
                </Setter>
                <Setter Property="ScrollViewer.HorizontalScrollBarVisibility"
                        Value="Disabled" />
            </Style>

        </ResourceDictionary>
    </Window.Resources>

    <DockPanel Name="MainPanel" LastChildFill="True">
        <StackPanel DockPanel.Dock="Bottom" Orientation="Horizontal">
            <Expander IsExpanded="False" ExpandDirection="Up" Header="Controls" >
                <StackPanel Orientation="Horizontal">
                    <Button HorizontalAlignment="Left" Name="btnPrevious" 
                    Width="75" Height="48" 
                    Command="MediaCommands.PreviousTrack">Previous</Button>
                    <Button Name="btnPlay" HorizontalAlignment="Left" 
                    Width="75" Height="48" 
                    Command="MediaCommands.Play"
                    >Play</Button>
                    <Button Name="btnNext" Width="75" Height="48" 
                    Command="MediaCommands.NextTrack">Next</Button>
                    <Button HorizontalAlignment="Right" Name="btnStop" 
                    Width="75" Height="48" 
                    Command="MediaCommands.Stop">Stop</Button>
                </StackPanel>
            </Expander>

            <Expander IsExpanded="False" ExpandDirection="Up" Header="Touch" >
                <mydc:SignExtender>
                    <mydc:SignExtender.InputBindings>
                        <mydi:SignBinding SignAction="Left" Command="MediaCommands.Stop" />
                        <mydi:SignBinding SignAction="Right" Command="MediaCommands.Play" />
                        <mydi:SignBinding SignAction="Down" Command="MediaCommands.NextTrack" />
                        <mydi:SignBinding SignAction="Up" Command="MediaCommands.PreviousTrack" />
                    </mydc:SignExtender.InputBindings>
                    <DockPanel Width="139" Height="79" Background="LightGray">
                    </DockPanel>
                </mydc:SignExtender>
            </Expander>

            <Expander IsExpanded="True" ExpandDirection="Up" Header="Sound" Width="200" >
                <StackPanel Margin="10">
                    <Label>Volume</Label>
                    <Slider Value="{Binding Path=Volume}" />
                    <Label>Mute</Label>

                </StackPanel>
            </Expander>
        </StackPanel>

        <StackPanel DockPanel.Dock="Right">
            <Expander IsExpanded="True" ExpandDirection="Left" Header="Current" >
                <StackPanel Width="200">
                    <StackPanel Height="100">
                        <Label Content="{Binding Path=CurrentMedia.Name}"/>
                    </StackPanel>
                </StackPanel>
            </Expander>

            <Expander IsExpanded="True" ExpandDirection="Left" Header="Album" >
                <StackPanel Width="200">
                    <StackPanel Height="100">
                        <Label Content="{Binding Path=Albums/Name}"/>
                        <Label Content="{Binding Path=Albums/Artist.Name}"/>
                    </StackPanel>
                    <StackPanel>
                        <ListBox Name="Tracks" ItemsSource="{Binding Path=Albums/Tracks}"
                            IsSynchronizedWithCurrentItem="true">
                        </ListBox>
                    </StackPanel>
                </StackPanel>
            </Expander>

        </StackPanel>

        <mydc:SpeechExtender>
            <mydc:SpeechExtender.InputBindings>
                <mydi:SpeechBinding ChoiceText="Stop" Command="MediaCommands.Stop" />
                <mydi:SpeechBinding ChoiceText="Play" Command="MediaCommands.Play" />
                <mydi:SpeechBinding ChoiceText="Next" Command="MediaCommands.NextTrack" />
                <mydi:SpeechBinding ChoiceText="Previous" Command="MediaCommands.PreviousTrack" />
            </mydc:SpeechExtender.InputBindings>
        </mydc:SpeechExtender>

        <mydc:SignExtender>
            <mydc:SignExtender.InputBindings>
                <mydi:SignBinding SignAction="Left" Command="MediaCommands.Stop" />
                <mydi:SignBinding SignAction="Right" Command="MediaCommands.Play" />
                <mydi:SignBinding SignAction="Down" Command="MediaCommands.NextTrack" />
                <mydi:SignBinding SignAction="Up" Command="MediaCommands.PreviousTrack" />
            </mydc:SignExtender.InputBindings>

            <ListBox Name="lbxAlbums" Style="{StaticResource WrapItemTemplate}" 
                         Width="Auto" Height="Auto" 
                         VerticalAlignment="Stretch" VerticalContentAlignment="Top"
                         ItemsSource="{Binding Path=Albums}" IsSynchronizedWithCurrentItem="true">

                <ListBox.InputBindings>
                    <MouseBinding Command="MediaCommands.Play" MouseAction="LeftDoubleClick" />
                </ListBox.InputBindings>
            </ListBox>

        </mydc:SignExtender>

    </DockPanel>
</mydc:GazeWindow>
